<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    * {
        margin: 0;
        padding: 0;
    }

    body {
        background-image: url(./image/csmy2.jpg);
        background-repeat: no-repeat;
        background-size: cover;
    }

    .container {
        height: 60px;
        width: 100;
        background-color: rgba(23, 20, 20, 0.4);
        /* 弹性布局 */
        display: flex;
        align-items: center;
    }

    .container span img {
        height: 50px;
        width: 50px;
        margin-top: 10px;
        margin-left: 10px;
        border-radius: 50%;
    }

    .space {
        width: 70%;
    }

    .container span a {
        text-decoration: none;
        padding: 0 10px;
    }
</style>

<body>
    <div class="container">
        <span class><img src="./image/csmy.jpg" alt=""></span>
        <span class="space"></span>
        <span class="link"><a href="http://47.115.227.93:8080/listshow">已备份文件</a></span>
        <span class="link"><a href="http://47.115.227.93:8080/Upload.html">提交文件</a></span>
        <span class="link"><a href="http://47.115.227.93:8080/logout">登出</a></span>
    </div>
    <div>
        <div class="message"></div>
        <div class="self-introduction"></div>
    </div>
</body>
<script>
    //获取url
    let url = window.location.href;
    if (url.lastIndexOf("?") != -1) {
        url = decodeURI(url);//解码
        //找到问号
        let pos = url.lastIndexOf("?");
        //切割后面的内容
        let message = url.slice(pos + 1);
        //&分隔符会被识别为%26
        if (message.lastIndexOf('%26') == -1)//登出
        {
            delCookie("username");
            //重定向,防止持续输出
            window.location.href = "http://47.115.227.93:8080/HomePage.html";
            //输出
            alert("退出登录成功");
        }
        else {
            //TODO
        }
    }

    //删除cookie
    function delCookie(name)
    {
        var exp = new Date();
        exp.setTime(exp.getTime() - 1);
        var cval = getCookie(name);
        if (cval != null) 
        {
            document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString()+";path=/";
        }
    }

    //检测cookie
    checkCookie();

    //获取cookie
    function getCookie(cname) {
        var name = cname + "=";
        var ca = document.cookie.split(';');
        for (var i = 0; i < ca.length; i++) {
            var c = ca[i].trim();
            if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
        }
        return "";
    }

    //检测cookie
    function checkCookie() {
        var username = getCookie("username");
        if (username != "") {
            let pos = username.indexOf(',');
            let message = username.slice(0, pos);
            alert("欢迎 " + message);
        }
        else {
            //重定向,防止持续输出
            window.location.href = "http://47.115.227.93:8080/LogIn.html";
            //输出
            alert("你还未登录");

            // username = prompt("Please enter your name:","");
            // if (username!="" && username!=null)
            // {
            // setCookie("username",username,365);
            // }
        }
    }
</script>

</html>